﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace SSISForSAPComponents
{
    public partial class SapDataSourcePipelineMapingEdit : Form
    {
        DataTable _tableMaping;
        IDTSInput100 _input;
        public SapDataSourcePipelineMapingEdit()
        {
            InitializeComponent();
            
        }
        private class Col
        {
            string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            int iD;

            public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
        }
        public SapDataSourcePipelineMapingEdit(DataTable tableMaping, IDTSInput100 input)
            : this()
        {
            _tableMaping = tableMaping;
            _input = input;
             
        }

        private void SapDataSourcePipelineMapingEdit_Load(object sender, EventArgs e)
        {

            try
            {
                InputColumn.ValueMember = "ID";
                InputColumn.DisplayMember = "Name";
                InputColumn.Selected = true;
                List<Col> cols = new List<Col>();
                Col colnull = new Col();
                colnull.ID = 0;
                colnull.Name = "<Select>";
                cols.Add(colnull);
                foreach (IDTSInputColumn100 col90 in this._input.InputColumnCollection)
                {
                    Col col = new Col();
                    col.ID = col90.ID;
                    col.Name = col90.Name;
                    cols.Add(col);
                }

                InputColumn.DataSource = cols;

                //InputColumn.
                dataGridView1.DataError += new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
                this.dataGridView1.DataSource = _tableMaping;
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
        }

        void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            //dataGridView1.Rows[e.RowIndex].Cells[1].Value = 0;  
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this._tableMaping.AcceptChanges(); 
            this.Close(); 
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this._tableMaping.RejectChanges(); 
            this.Close(); 
        }
    }
}
